<template>
  <div>
    <div class="stuinfo_personal_title">学生个人信息查询</div>
    <el-row>
      <el-col :span="6" :offset="8">
        <el-input v-model="stu_id"></el-input>
      </el-col>
      <el-col :span="4" :offset="1">
        <el-button @click="getStuInfo">搜索</el-button>
      </el-col>
    </el-row>
    <div class="result_wrap" v-if="show">
      <img :src="result[0].stu_head_img" alt="" width="200px" height="200px" />
      <div class="table_wrap">
        <el-table :data="result" style="width: 100%" border>
          <el-table-column prop="stu_id" label="学号" width="180">
          </el-table-column>
          <el-table-column prop="stu_name" label="姓名" width="180">
          </el-table-column>
          <el-table-column prop="stu_jg" label="籍贯"> </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { req_stu_info_personal } from "@/api/stuInfo.js";
export default {
  data() {
    return {
      stu_id: "",
      result: [],
      show: false,
    };
  },
  methods: {
    async getStuInfo() {
      console.log(this.stu_id);
      let result = await req_stu_info_personal(this.stu_id);
      console.log(result);
      // 服务器有该数据
      // 服务器当中要是没有该条数据

      if (result.data.length > 0) {
        this.result = result.data;
        this.show = true;
        console.log(this.result);
      } else {
        this.$message({
          message: "该学号不存在，请重新输入",
          type: "error",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
div {
  .stuinfo_personal_title {
    height: 30px;
    text-align: center;
    font-size: 25px;
    font-weight: 700;
    margin-bottom: 20px;
  }
  .result_wrap {
    text-align: center;
    .table_wrap {
      height: 150px;
      .el-table__header-wrapper {
        height: 50px;
      }
      /deep/ .el-table__body-wrapper {
        height: 50px;
        .el-table__body {
          height: 50px;
        }
      }
    }
  }
}
</style>